package com.school.demo.util;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;

import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.GsonHttpMessageConverter;

//import com.google.gson.GsonBuilder;
//import com.google.gson.JsonElement;
//import com.google.gson.JsonParser;
//import com.google.gson.JsonSerializationContext;
//import com.google.gson.JsonSerializer;

import springfox.documentation.spring.web.json.Json;

/**
 * @program: demo
 * @description: gson配置类, 用于解决gson不支持swigger
 * @author: Charlotte
 * @create: 2021-03-01 10:41
 **/
public class GsonConfig {
//    public class GsonConfig implements JsonSerializer<Json>{
//    @Bean
//    public HttpMessageConverters customConverters() {
//
//        Collection<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
//        GsonHttpMessageConverter gsonHttpMessageConverter = new GsonHttpMessageConverter();
//        gsonHttpMessageConverter.setGson(
//                new GsonBuilder()
//                        .setDateFormat("yyyy-MM-dd")
//                        .registerTypeAdapter(Json.class, new GsonConfig())
//                        .create());
//        messageConverters.add(gsonHttpMessageConverter);
//
//        return new HttpMessageConverters(true, messageConverters);
//    }
//
//    @SuppressWarnings("deprecation")
//    @Override
//    public JsonElement serialize(Json json, Type type, JsonSerializationContext context) {
//        final JsonParser parser = new JsonParser();
//        return parser.parse(json.value());
//    }

}
